/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package timeConversion;

import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

/**
 *
 * @author Duc
 */
public class DateToGregorian {
/**
* Transform a date in a long to a GregorianCalendar
*
* @param date
* @return
*/
    public static XMLGregorianCalendar long2Gregorian(long date) {
        DatatypeFactory dataTypeFactory;
        try {
            dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(date);
        return dataTypeFactory.newXMLGregorianCalendar(gc);
    }

    /**
     * Transform a date in Date to XMLGregorianCalendar
     */
    public static XMLGregorianCalendar date2Gregorian(Date date) {
        return long2Gregorian(date.getTime());
    }
}
